class Solution {
public:
    vector<vector<string>> ans;
    string t;
    int n;
    int f[20][20] = { 0 };
    void dfs(int x, vector<string>& ss) {
        if (x == n) {
            ans.push_back(ss);
            return;
        }
        for (int i = x; i < n; i++) {
            if (f[x][i]) {
                cout << "x===" << x << endl;
                cout << "i===" << i << endl;
                ss.push_back(t.substr(x, i - x + 1));
                dfs(i + 1, ss);
                ss.pop_back();
            }
        }

    }
    vector<vector<string>> partition(string s) {
        t = s;
        n = s.size();
        memset(f, 1, sizeof(f));
        for (int i = n - 1; i >= 0; i--) {
            for (int j = i + 1; j < n; j++) {
                f[i][j] = (s[i] == s[j]) && f[i + 1][j - 1];
            }
        }
        vector<string>ss;
        dfs(0, ss);
        return ans;
    }
};